<template>
  <div class="baseInfo">
    <div class="duty clearfix">
      <p class="p1" >基盘信息</p>
      <p class="p2" @click="goBase()">基盘客户管理</p>
    </div>
    <FormPanel
      ref="baseInfo"
      :list="formList"
      :cols="3"
      :formType="'show'"
      labelWidth="110"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
      style="margin-top: 10px"
    />
    <!-- 已购车辆 -->
    <BreakSpace label="已购车辆" :containerStyle="{ marginBottom: '10px' }"/>
    <FilterTable
      ref="table"
      :columns="columns"
      height="auto"
      :dataSource="bugCarList"
      :isPagination='false'
      :isSelectColumn='false'
      :onColumnsChange="columns1 => this.columns1 = columns1"
    ></FilterTable>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment'
import { getBaseInfoById } from '@/api/potenCus/customer/cust1Manage'
import { auditDistPotentialDetail } from '@/api/potenCus/customer/cust1Manage'
import { formatDat } from '@/utils/validate';
import Cookies from 'js-cookie';
export default {
  name: 'baseInfo',
  mixins: [dictionary],
  props: {
    rowData: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      formList: this.createFormList(),
      columns: this.createTableColumns(),
      dataSource: null,
      bugCarList: []
    }
  },
  mounted () {
    console.log('mounted', this.rowData)
  },
  created () {
    this.init()
  },
  activated () {
    this.init()
  },
  methods:{
    init () {
      console.log('少给我挖坑', this.rowData)
      this.actionId = this.rowData.actionId
      this.potentialCustomerId = this.rowData.potentialCustomerId?this.rowData.potentialCustomerId:this.rowData.potentialCustomersId
      this.customerBusinessId = this.rowData.costomerBusinessId
      // if (this.actionId && this.potentialCustomerId && this.customerBusinessId) {
      if (this.potentialCustomerId) {
        this.auditDistPotentialDetail()
      } else {
      }
    },
    auditDistPotentialDetail(){
      auditDistPotentialDetail(this.actionId, this.potentialCustomerId, this.customerBusinessId).then(res => {
        console.log('基盘的明细', res)
        this.formList.forEach(item => {
          if (item.fieldName === 'level') {
            if(res.data.level){
              item.initialValue = Number(res.data.level)
            }
          } else {
            item.initialValue = res.data[item.fieldName]
          }
        })
        // 已购车辆
        this.bugCarList = res.data.salesOrderInfoVOS
      })
    },
    createFormList () {
      return [
        {
          type: 'SELECT',
          label: '客户等级',
          fieldName: 'level',
          placeholder: '',
          itemList: this.createDictList('7049'),
        },
        {
          type: 'INPUT_NUMBER',
          label: '已购车辆(台)',
          fieldName: 'purchased',
          placeholder: '',
        },
        {
          type: 'INPUT_NUMBER',
          label: '续购(台)',
          fieldName: 'renewal',
          placeholder: '',
        },
        {
          type: 'INPUT_NUMBER',
          label: '转介绍(台)',
          fieldName: 'introductionNumber',
          placeholder: '',
        },
      ]
    },
    createTableColumns () {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '销售单号',
          dataIndex: 'viNo',
          width: 180,
        },
        {
          title: '车系',
          dataIndex: 'seriesName',
        },
        {
          title: '车型',
          dataIndex: 'modelName',
        },
        {
          title: '配置',
          dataIndex: 'packageName',
          width: 200,
        },
        {
          title: '颜色',
          dataIndex: 'colorName',
        },
        {
          title: 'VIN',
          dataIndex: 'salesVin',
          width: 180,
        },
        {
          title: '车辆价格',
          dataIndex: 'vehiclePrice',
          width: 100,
        },
        {
          title: '出库日期',
          dataIndex: 'stockInOutDate',
          width: 200,
          render: props => {
            return <span>{ formatDat(props.row.stockInOutDate) }</span>;
          }
        },
      ]
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    goBase(){
      this.$router.push("/potenCus/basePlate/cust1/index")
      Cookies.set('baseNO', this.rowData.mobilePhone);
      this.$emit('myClallback')
    },
  }
}
</script>

<style lang="less" scoped>
.baseInfo{
  .duty{
      line-height: 40px;
      background: #E2E8F3;
      padding-left: 10px;
      padding-right: 30px;
      margin-bottom: 20px;
      .p1{
        float: left;
      }
      .p2{
        float: right;
        cursor: pointer;
      }
  }
}
</style>
